﻿using Devonline.Entity;
using Microsoft.OData.Edm;
using Microsoft.OData.ModelBuilder;

namespace Devonline.Identity.Admin
{
    public class Utility
    {
        /// <summary>
        /// 获取 odata 的 edm model
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="context"></param>
        /// <returns></returns>
        public static IEdmModel BuildEdmModel()
        {
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<Parameter>(nameof(IdentityDbContext.Parameters));
            builder.EntitySet<Level>(nameof(IdentityDbContext.Levels));
            builder.EntitySet<Group>(nameof(IdentityDbContext.Groups));
            builder.EntitySet<Role>(nameof(IdentityDbContext.Roles));
            builder.EntitySet<User>(nameof(IdentityDbContext.Users));
            builder.EntitySet<Resource>(nameof(IdentityDbContext.Resources));
            builder.EntitySet<AccessRule>(nameof(IdentityDbContext.AccessRules));
            builder.EntitySet<AccessApply>(nameof(IdentityDbContext.AccessApplies));
            builder.EntitySet<AccessRecord>(nameof(IdentityDbContext.AccessRecords));
            //builder.EntityType<Resource>().ComplexProperty(x => x.Level).IsNavigable();
            return builder.EnableLowerCamelCase().GetEdmModel();
        }
    }
}
